#include <ecal/ecal.h>
#include <ecal/msg/protobuf/publisher.h>

#include <iostream>
#include <thread>

#include "protocol/hello_world.pb.h"

int main(int argc, char** argv) {
  // Initialize eCAL and create a protobuf publisher
  eCAL::Initialize(argc, argv, "Hello World Protobuf Publisher");
  eCAL::protobuf::CPublisher<example::HelloWorld> publisher("hello_world_protobuf");

  // Create a protobuf message object
  example::HelloWorld hello_world_message;

  unsigned int id = 0;
  while (eCAL::Ok()) {
    std::string message;
    hello_world_message.set_name("Ivan");
    hello_world_message.set_msg("Hello World from Protobuf!");
    hello_world_message.set_id(id++);

    // Send the message
    publisher.Send(hello_world_message);
    std::cout << "Sent message: " << id << std::endl;
    
    // sleep 500 ms
    eCAL::Process::SleepMS(500);
  }

  // finalize eCAL API
  eCAL::Finalize();
}